<template>
  <div class="article">
    <div class="content-top">
      <p class="header-title">样本添加标引</p>
      <p>
        <el-button class="saveBtn" icon="el-icon-document" @click="save">
          保存</el-button
        >
      </p>
    </div>
    <div ref="outer" class="article-content">
      <div ref="inner" class="content-left" :style="width">
        <div class="article-body">
          <div v-html="details.xianglannr"></div>
        </div>
      </div>
      <div class="content-right">
        <div class="right-body">
          <div class="title">决定号：{{ queryParams.juedingh }}</div>
          <div class="form-group">
            <div
              class="form-line"
              v-for="(item, index) in details.biaoyinLIst"
              :key="index"
            >
              <p class="label">{{ item.biaoyinxmc }}</p>
              <el-input
                v-model="item.biaoyinnr"
                v-if="item.biaoyinxlx == 'text'"
                clearable
              ></el-input>
              <el-select
                v-model="item.biaoyinnr"
                class="select-form"
                v-if="item.biaoyinxlx == 'select'"
              >
                <el-option
                  v-for="item in item.biaoyinxxz.split(',')"
                  :key="item"
                  :label="item"
                  :value="item"
                />
              </el-select>
              <el-date-picker
                v-if="item.biaoyinxlx == 'date'"
                v-model="item.biaoyinnr"
                class="select-form"
                clearable
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="年/月/日"
              />
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { sampleInfo,indexAddContent } from "@/api/sampleBank";
export default {
  name: "Article",
  data() {
    return {
      width: "width:75%",
      details: {},
      queryParams: {},
    };
  },
  mounted() {
    this.queryParams = JSON.parse(this.$route.query.row);
    console.log(this.queryParams, "-----");
    this.width = `width:${this.$refs.outer.clientWidth - 307}px`;
    window.onresize = () => {
      return (() => {
        this.width = `width:${this.$refs.outer.clientWidth - 307}px`;
      })();
    };
    this.getDetail();
  },
  methods: {
    // 获取详情
    getDetail() {
      sampleInfo(this.queryParams).then((res) => {
        console.log(res);
        this.details = res.data;
      });
    },
    // 保存
    save() {
      const data = {
        yangbenid: this.details.yangbenid,
        yangbenkid: this.details.yangbenkid,
        biaoyinLIst: this.details.biaoyinLIst.map((item) => {
          return {
            biaoyinxid: item.biaoyinxid,
            biaoyinnr: item.biaoyinnr,
          };
        }),
      };
      indexAddContent(data).then(res=>{
        if(res.code==200){
          this.$message.success('保存成功')
        }
      })
    },
  },
};
</script>
<style lang="scss">
.article {
  .content-top {
    display: flex;
    justify-content: space-between;
    margin: 0 auto;
    width: 1200px;
    align-items: center;
    .header-title {
      font-size: 20px;
      color: #303133;
    }
    .saveBtn {
      background: #3057b5;
      color: #fff;
      &.el-button {
        padding: 10px 13px;
        font-size: 13px;
        border-radius: 6px;
      }
    }
  }
  &-content {
    display: flex;
    justify-content: space-between;
    margin: 0 auto;
    width: 1200px;
    .content-left {
      width: 75%;
      .article-body {
        background: #fff;
        height: calc(100vh - 240px);
        padding: 15px;
        box-sizing: border-box;
        border: 1px solid #dcdfe6;
        border-radius: 5px;
        overflow-y: auto;
        &::-webkit-scrollbar-track-piece {
          background-color: #f5f5f5;
        }
        &::-webkit-scrollbar {
          width: 5px;
          height: 5px;
        }
        &::-webkit-scrollbar-thumb {
          background-color: #c2c2c2;
          background-clip: padding-box;
          min-height: 20px;
          border-radius: 10px;
        }
        p {
          font-size: 16px;
          text-indent: 32px;
          margin: 0;
          line-height: 1.5;
          color: #606266;
        }
      }
    }
    .content-right {
      width: 267px;
      .right-body {
        background: #fff;
        padding: 15px;
        height: calc(100vh - 240px);
        border: 1px solid #dcdfe6;
        border-radius: 5px;
        .title {
          font-size: 16px;
          font-weight: 600;
        }
        .select-form {
          width: 100%;
        }
      }
    }
  }
}
</style>
